/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	ParameterBinderShaderResource.cpp
*
*	Comments	-	See ParameterBinderShaderResource.h
*
**************************************************************************************/
#include "../Include/ParameterBinderShaderResource.h"
#include "../Include/ParameterShaderResource.h"
#include "../Include/Texture2D.h"
#include "../Include/StructuredBuffer.h"
#include "../Include/Buffer.h"

namespace Pulse
{
	ParameterBinderShaderResource::~ParameterBinderShaderResource( void )
	{
		PSX_SafeRelease( m_pResItem );
	}

	ParameterBinderShaderResource::ParameterBinderShaderResource( void )
		: m_pResItem( PSX_NULL ), m_pData( PSX_NULL )
	{
		
	}

	ParameterBinderShaderResource::ParameterBinderShaderResource( IParameter *pParam )
		: m_pResItem( PSX_NULL ), m_pData(PSX_NULL)
	{
		SetParameter( pParam );
	}

	void ParameterBinderShaderResource::SetAsShaderResource( Texture2D *pTexture )
	{
		IResourcePoolItem *pResItem = pTexture;

		PSX_SafeRelease( m_pResItem );

		m_pResItem = pResItem;

		if ( pResItem )
		{
			pResItem->AddRef();
		}

		SetData( pTexture );
	}

	void ParameterBinderShaderResource::SetAsShaderResource( StructuredBuffer *pBuffer )
	{
		IResourcePoolItem *pResItem = pBuffer;

		PSX_SafeRelease( m_pResItem );

		m_pResItem = pResItem;

		if ( pResItem )
		{
			pResItem->AddRef();
		}

		SetData( pBuffer );
	}

	void ParameterBinderShaderResource::SetAsShaderResource( Buffer *pBuffer )
	{
		IResourcePoolItem *pResItem = pBuffer;

		PSX_SafeRelease( m_pResItem );

		m_pResItem = pResItem;

		if ( pResItem )
		{
			pResItem->AddRef();
		}

		SetData( pBuffer );
	}

	void ParameterBinderShaderResource::SetData( const ShaderResource *pData ) 
	{ 
		m_pData = pData; 
	}

	void ParameterBinderShaderResource::BindValue( void )
	{
		m_pShaderResourceParam->SetResource( m_pData );
	}

}